def final_7(a):   
    if a == 1: return False   
    test = True   
    k = a - 1   
    while k > 1:   
        if not a % k:   
            test = False               
            break   
        k -= 1       
    return test  
     
h = input() 
q = [] 
for i in range(len(h) + 1): 
    for k in range(i,len(h) + 1): 
        if i == k: 
            continue 
        a = int(h[i:k]) 
        if final_7(a): 
            q += [a] 
print(max(q) if q else 0)
